package com.moonshineproject.utils
{
	public class HtmlFormatter
	{
		/*
			HTML encode replacements. Use %s for substitution.
		*/
		public static function sprintf(str:String, ...replacements):String
		{
			// TODO: Use the sprintf lib that is on google code instead? (MIT)
			var lastIndex:int = 0;
			var index:int = 0;
			
			var ret:String = "";
			
			for each (var repl:String in replacements)
			{
				repl = TextUtil.htmlEscape(repl);
				
				index = str.indexOf("%s", lastIndex);
				if (index == -1) continue;
				ret += str.substring(lastIndex, index);
				ret += repl;
				
				lastIndex = index+2;
			}
			
			ret += str.substring(lastIndex);
			
			return ret;
		}

	}
}